package com.bihu.bihudemo.controller;

import com.bihu.bihudemo.config.MqConfig;
import com.bihu.bihudemo.entity.User;
import com.bihu.bihudemo.mq.PostMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class testController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/index")
    public String hello(){
        return "world";
    }

    @GetMapping("/hello")
    public String hello2(){
        return  "hello";
    }

    @GetMapping("/sendMsg")
    public String testQueue(){
        PostMessage message = new PostMessage();
        User user = new User();
        user.setUsername("xiongipp");
        user.setEmail("xiongipp@outlook.com");
        message.setUser(user);
        rabbitTemplate.convertAndSend("bihu", MqConfig.EmailKEY,message);
        return "ok";
    }
}
